#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main()
{	
	umask(0);
	//int fd = open("log.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666);
	//int fd = open("log.txt", O_CREAT | O_WRONLY | O_APPEND, 0666);
	int fd = open("log.txt", O_RDONLY);
	if(fd < 0){
		perror("open fail");
		exit(1);
	}
	
	//const char* msg = "hello linux\n";
	char buffer[1024];
	//int cnt = 10;
	while(1){
		//write(fd, msg, strlen(msg));
		int check = read(fd, buffer, sizeof(buffer));
		if(check > 0){
			buffer[check] = '\0';
			printf("%s", buffer);
		}
		else if(check == 0){
			break;
		}
	}
	
	close(fd);

	return 0;
}
